package com.fingard.dsp.bank.directbank.ccb02;


import java.util.HashMap;

import com.fingard.dsp.bank.directbank.bankInterface.IOtherElse;
import com.fingard.dsp.bank.reqrespobj.otherelse.ReqOtherElse;
import com.fingard.dsp.bank.reqrespobj.otherelse.RetAtsOtherElse;
import com.fingard.dsp.bank.reqrespobj.single.ReqSingle;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

public class CCB02OtherElse extends CCB02Base implements IOtherElse {
	
	public RetAtsOtherElse d_else(ReqOtherElse p_reqElse) throws Exception{
		RetAtsOtherElse retAts = new RetAtsOtherElse(p_reqElse.reqHeader);
		retAts.writeBankRetStr("未知的TransType：" + p_reqElse.reqHeader.transType);
		return retAts;
	}
	
	/**外联平台帐户信息查询*/
	public HashMap<String,String> exec6W0101(ReqSingle p_req1908) throws Exception{
		HashMap<String,String> retHash = new HashMap<String,String>();
		try {
			//赋值通用参数
			CCB02Header bankHeader = new CCB02Header();
			bankHeader.TX_CODE = "6W0101";
			bankHeader.REQUEST_SN = this.getQryTransID();
			XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
			//写入通用的头部节点
			writeCommonHeader(xmlWriter, bankHeader);
			xmlWriter.writeStartElement("TX_INFO");
			
			String[] tmpATSAreas = p_req1908.singleDetail.recArea.split("_");
			String ACC_BRANCH_CODE = tmpATSAreas[0];//一级行号
			
			//String ACC_BRANCH_CODE = p_req1908.singleDetail.recAct.substring(0, 3);
            //if (ACC_BRANCH_CODE.length() == 3){
            //	ACC_BRANCH_CODE += "000000";
            //}
			
			xmlWriter.writeElementString("ACC_BRANCH_CODE", ACC_BRANCH_CODE);
			xmlWriter.writeElementString("ACC_NO", p_req1908.singleDetail.recAct);
			xmlWriter.writeElementString("ACC_NO1", p_req1908.singleDetail.payAct);
			xmlWriter.writeEndElement();
			xmlWriter.writeEndDocument();
			String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
			if(tmpStrRet[0].length() == 0){
				StringBuilder tmpSbMsg = new StringBuilder();
				XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
				if(tmpBkReader != null){
					retHash.put("UBANK_NO", tmpBkReader.getSimpleTextNotNull("UBANK_NO"));
					retHash.put("COUNTER_NO", tmpBkReader.getSimpleTextNotNull("COUNTER_NO"));
				}
			}	
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retHash;
	}
}
